import 'startup/startup.js';
//..加载主文件
import App from 'layout/app'
import Root from 'startup/root.vue'
import Mounter from 'startup/mounter.vue'
import Wechat from 'startup/wechat.vue'
//..加载常规页面
import NotFound from 'layout/notfound.vue'
import Login from 'layout/login.vue'

import Home from 'layout/home.vue';

//..路由
import VueRouter from 'vue-router'
Vue.use(VueRouter)
	//..面包屑
import VueBreadcrumbs from 'startup/breadcrumbs.js'
Vue.use(VueBreadcrumbs)
	//..resource
import 'lib/resource.js'

const router = new VueRouter({
	linkActiveClass: 'active',
	transitionOnLoad: true
})

const map = {
	'*': {
		component: NotFound
	},
	'/login': {
		component: Login
	},
	'/': {
		component: App,
		subRoutes: {
			'/home': {
				component: Home,
				breadcrumb: "首页"
			},
			'/': {
				component: Mounter,
				breadcrumb: "系统管理",
				subRoutes: {
					'/admin': {
						breadcrumb: "管理员管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '操作员添加',
								component: function(resolve) {
									require(['system/admin/create.vue'], resolve)
								}
							},
							'/list': {
								breadcrumb: '操作员维护',
								component: function(resolve) {
									require(['system/admin/list.vue'], resolve)
								}
							}
						}
					},

					'/role': {
						breadcrumb: "角色管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '角色添加',
								component: function(resolve) {
									require(['system/role/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '角色维护',
								component: function(resolve) {
									require(['system/role/list.vue'], resolve);
								}
							}
						}
					},
					'/merchant': {
						breadcrumb: "商户管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '商户添加',
								component: function(resolve) {
									require(['system/merchant/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '商户维护',
								component: function(resolve) {
									require(['system/merchant/merchantList.vue'], resolve);
								}
							}
						}
					},
                    '/mchtUsr': {
                        breadcrumb: "商户管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '店员添加',
                                component: function(resolve) {
                                    require(['system/mchtUsr/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '店员维护',
                                component: function(resolve) {
                                    require(['system/mchtUsr/list.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/merSett': {
                        breadcrumb: "商户管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '商户结算方式添加',
                                component: function(resolve) {
                                    require(['system/merSett/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '商户结算方式维护',
                                component: function(resolve) {
                                    require(['system/merSett/list.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/mchtadvier': {
                        breadcrumb: "商户广告管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '商户广告新增',
                                component: function(resolve) {
                                    require(['system/mchtadvier/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '商户广告维护',
                                component: function(resolve) {
                                    require(['system/mchtadvier/list.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/advertCode': {
                        breadcrumb: "广告二维码",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '广告二维码内容',
                                component: function(resolve) {
                                    require(['system/advertCode/advert.index.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '广告二维码时间',
                                component: function(resolve) {
                                    require(['system/advertCode/time.index.vue'], resolve);
                                }
                            }
                        }
                    },
					'/cuisine': {
						breadcrumb: "商品类型管理",
						component: Mounter,
						subRoutes: {
							'/varietyCreate': {
								breadcrumb: '商品添加',
								component: function(resolve) {
									require(['system/cuisine/varietyCreate.vue'], resolve);
								}
							},
							'/menuCreate': {
								breadcrumb: '商品类型添加',
								component: function(resolve) {
									require(['system/cuisine/menuCreate.vue'], resolve);
								}
							},
							'/menuList': {
								breadcrumb: '商品类型维护',
								component: function(resolve) {
									require(['system/cuisine/menuList.vue'], resolve);
								}
							},
							'/varietyList': {
								breadcrumb: '商品维护',
								component: function(resolve) {
									require(['system/cuisine/varietyList.vue'], resolve);
								}
							}
						}
					},
					'/coupons': {
						breadcrumb: "电子券管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '电子券添加',
								component: function(resolve) {
									require(['system/coupons/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '电子券维护',
								component: function(resolve) {
									require(['system/coupons/list.vue'], resolve);
								}
							},
                            '/marketRule': {
                                breadcrumb: '绑定营销规则',
                                component: function(resolve) {
                                    require(['system/coupons/marketRule.vue'], resolve);
                                }
                            },
                            '/authorizeList': {
                                breadcrumb: '电子券授权列表',
                                component: function(resolve) {
                                    require(['system/coupons/authorizeList.vue'], resolve);
                                }
                            },
                            '/voucher': {
                                breadcrumb: '消费验券',
                                component: function(resolve) {
                                    require(['system/coupons/voucher.vue'], resolve);
                                }
                            }
						}
					},
                    '/ThirdParty-Coupons': {
                        breadcrumb: "第三方电子券查询",
                        component: Mounter,
                        subRoutes: {
                            '/list': {
                                breadcrumb: '第三方电子券查询',
                                component: function(resolve) {
                                    require(['system/ThirdParty-Coupons/list.vue'], resolve);
                                }
                            }
                        }
                    },
					'/activity': {
						breadcrumb: "活动管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '活动添加',
								component: function(resolve) {
									require(['system/activities/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '活动维护',
								component: function(resolve) {
									require(['system/activities/list.vue'], resolve);
								}
							}
						}
					},
					'/txns': {
						breadcrumb: "流水管理",
						component: Mounter,
						subRoutes: {
							'/txnCou': {
								breadcrumb: '电子券交易查询',
								component: function(resolve) {
									require(['system/txns/couList.vue'], resolve);
								}
							},
							'/txnPay': {
								breadcrumb: '支付交易查询',
								component: function(resolve) {
									require(['system/txns/payList.vue'], resolve);
								}
							},

							'/txnOrder': {
								breadcrumb: '订单查询',
								component: function(resolve) {
									require(['system/txns/orderList.vue'], resolve);
								}
							},
                            '/marketFlow': {
                                breadcrumb: '营销流水查询',
                                component: function(resolve) {
                                    require(['system/txns/marketFlow.vue'], resolve);
                                }
                            },
                            '/mchtWallet': {
                                breadcrumb: '商户钱包流水查询',
                                component: function(resolve) {
                                    require(['system/txns/mchtWallet.vue'], resolve);
                                }
                            },
                            '/deposit': {
                                breadcrumb: '商户押金管理',
                                component: function(resolve) {
                                    require(['system/txns/deposit.vue'], resolve);
                                }
                            }
						}
					},
                    '/delivery': {
                        breadcrumb: "发货管理",
                        component: Mounter,
                        subRoutes: {
                            '/delivery': {
                                breadcrumb: '发货管理',
                                component: function(resolve) {
                                    require(['system/delivery/delivery.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/pennyRule': {
                        breadcrumb: "营销分钱规则管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '分钱规则添加',
                                component: function(resolve) {
                                    require(['system/pennyRule/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '分钱规则维护',
                                component: function(resolve) {
                                    require(['system/pennyRule/list.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/settlementRule': {
                        breadcrumb: "营销分钱规则管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '结算分钱规则添加',
                                component: function(resolve) {
                                    require(['system/settlementRule/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '结算分钱规则维护',
                                component: function(resolve) {
                                    require(['system/settlementRule/list.vue'], resolve);
                                }
                            }
                        }
                    },

                    '/votingActivity': {
                        breadcrumb: "活动管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '投票活动添加',
                                component: function(resolve) {
                                    require(['system/votingActivity/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '投票活动管理',
                                component: function(resolve) {
                                    require(['system/votingActivity/list.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/channelCoupon': {
                        breadcrumb: "渠道券管理",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '渠道券添加',
                                component: function(resolve) {
                                    require(['system/channelCoupon/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '渠道券维护',
                                component: function(resolve) {
                                    require(['system/channelCoupon/list.vue'], resolve);
                                }
                            },
                            '/historyList': {
                                breadcrumb: '渠道历史券查询',
                                component: function(resolve) {
                                    require(['system/channelCoupon/historyList.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/couponDelivery': {
                        breadcrumb: "好券速递",
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '好券速递添加',
                                component: function(resolve) {
                                    require(['system/couponDelivery/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '好券速递维护',
                                component: function(resolve) {
                                    require(['system/couponDelivery/list.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/couponBanner': {
                        breadcrumb: "电子券广告",
                        component: Mounter,
                        subRoutes: {
                            '/bannerCreate':{
                                breadcrumb: '电子券广告添加',
                                component: function(resolve) {
                                    require(['system/couponBanner/bannerCreate.vue'], resolve);
                                }
                            },
                            '/bannerList':{
                                breadcrumb: '电子券广告维护',
                                component: function(resolve) {
                                    require(['system/couponBanner/bannerList.vue'], resolve);
                                }
                            }
                        }
                    },
                    '/deposit': {
                        breadcrumb: "钱包押金管理",
                        component: Mounter,
                        subRoutes: {
                            '/wallet': {
                                breadcrumb: '商云钱包查询',
                                component: function(resolve) {
                                    require(['system/deposit/wallet.vue'], resolve);
                                }
                            },
                            '/deposit': {
                                breadcrumb: '商户押金管理',
                                component: function(resolve) {
                                    require(['system/deposit/deposit.vue'], resolve);
                                }
                            },
                            '/mchtWallet': {
                                breadcrumb: '商户钱包流水查询',
                                component: function(resolve) {
                                    require(['system/deposit/mchtWallet.vue'], resolve);
                                }
                            },
                        }
                    },
					'/weights': {
						breadcrumb: "权重管理",
						component: Mounter,
						subRoutes: {
							'/list': {
								breadcrumb: '权重维护',
								component: function(resolve) {
									require(['system/weights/list.vue'], resolve);
								}
							}
						}
					},
					"/publish-articles": {
							breadcrumb: '文章管理',
							component: Mounter,
							subRoutes: {
								'/create': {
									breadcrumb: '文章添加',
									component: function(resolve) {
										require(['system/publish-articles/create.vue'], resolve);
									}
								},
								'/list': {
									breadcrumb: '文章维护',
									component: function(resolve) {
										require(['system/publish-articles/list.vue'], resolve);
									}
								}
							}
						},
					'/merchantSettled': {
						breadcrumb: "商户入驻",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb:'入驻申请',
								component: function(resolve) {
									require(['system/merchantSettled/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb:'入驻维护',
								component: function(resolve) {
									require(['system/merchantSettled/list.vue'], resolve);
								}
							}
						}
					},
					'/label': {
						breadcrumb: "标签管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb:'标签添加',
								component: function(resolve) {
									require(['system/label/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb:'标签维护',
								component: function(resolve) {
									require(['system/label/list.vue'], resolve);
								}
							}
						}
					},
					'/diningField': {
						breadcrumb: "商品字典管理",
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb:'商品字典添加',
								component: function(resolve) {
									require(['system/diningField/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb:'商品字典维护',
								component: function(resolve) {
									require(['system/diningField/list.vue'], resolve);
								}
							}
						}
					},
					"/adviertisement": {
						breadcrumb: '广告管理',
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '广告添加',
								component: function(resolve) {
									require(['system/adviertisement/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '广告维护',
								component: function(resolve) {
									require(['system/adviertisement/list.vue'], resolve);
								}
							}
						}
					},
					"/fee": {
						breadcrumb: '手续费管理',
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '手续费添加',
								component: function(resolve) {
									require(['system/fee/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '手续费维护',
								component: function(resolve) {
									require(['system/fee/list.vue'], resolve);
								}
							}
						}
					},
                    "/feedOpi": {
                        breadcrumb: '意见和反馈',
                        component: Mounter,
                        subRoutes: {
                            '/list': {
                                breadcrumb: '意见和反馈维护',
                                component: function(resolve) {
                                    require(['system/feedOpi/list.vue'], resolve);
                                }
                            }
                        }
                    },
					"/encourage": {
						breadcrumb: '激励管理',
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '激励添加',
								component: function(resolve) {
									require(['system/encourage/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '激励维护',
								component: function(resolve) {
									require(['system/encourage/list.vue'], resolve);
								}
							}
						}
					},
					"/systemMessage": {
						breadcrumb: '系统消息管理',
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '系统消息添加',
								component: function(resolve) {
									require(['system/systemMessage/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '系统消息维护',
								component: function(resolve) {
									require(['system/systemMessage/list.vue'], resolve);
								}
							}
						}
					},
					"/user": {
						breadcrumb: '用户管理',
						component: Mounter,
						subRoutes: {
							'/infoList': {
								breadcrumb: '用户信息查询',
								component: function(resolve) {
									require(['system/user/infoList.vue'], resolve);
								}
							},
							'/acountList': {
								breadcrumb: '用户账户查询',
								component: function(resolve) {
									require(['system/user/acountList.vue'], resolve);
								}
							}
						}
					},
                    "/version": {
                        breadcrumb: '软件版本管理',
                        component: Mounter,
                        subRoutes: {
                            '/create': {
                                breadcrumb: '版本添加',
                                component: function(resolve) {
                                    require(['system/version/create.vue'], resolve);
                                }
                            },
                            '/list': {
                                breadcrumb: '版本维护',
                                component: function(resolve) {
                                    require(['system/version/list.vue'], resolve);
                                }
                            }
                        }
                    },
				}
			},

			'/wechat': {
				breadcrumb: "微信管理",
				component: Mounter,
				subRoutes: {
					'/menu': {
						breadcrumb: '微信菜单管理',
						component: Wechat,
						subRoutes: {
							'/list': {
								breadcrumb: '自定义菜单管理',
								component: function(resolve) {
									require(['pages/wechat/menu/list.vue'], resolve);
								}
							}
						}
					},
					'/account': {
						breadcrumb: '账号管理',
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '绑定微信账户',
								component: function(resolve) {
									require(['pages/wechat/account/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '账户信息管理',
								component: function(resolve) {
									require(['pages/wechat/account/list.vue'], resolve);
								}
							}
						}
					},
					'/graphic': {
						breadcrumb: '图文管理',
						component: Wechat,
						subRoutes: {
							'/list': {
								breadcrumb: '图文管理',
								component: function(resolve) {
									require(['pages/wechat/graphic/list.vue'], resolve);
								}
							}
						}
					},
					'/resource': {
						breadcrumb: '素材管理',
						component: Wechat,
						subRoutes: {
							'/create': {
								breadcrumb: '素材上传',
								component: function(resolve) {
									require(['pages/wechat/resource/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '素材管理',
								component: function(resolve) {
									require(['pages/wechat/resource/list.vue'], resolve);
								}
							}
						}
					},
					'/user': {
						breadcrumb: '关注者管理',
						component: Wechat,
						subRoutes: {
							'/list': {
								breadcrumb: '关注者管理',
								component: function(resolve) {
									require(['pages/wechat/user/list.vue'], resolve);
								}
							}
						}
					},
					'/mass': {
						breadcrumb: '群发管理',
						component: Wechat,
						subRoutes: {
							'/send': {
								breadcrumb: '新建群发消息',
								component: function(resolve) {
									require(['pages/wechat/mass/send.vue'], resolve);
								}
							},
							'/search': {
								breadcrumb: '群发消息查询',
								component: function(resolve) {
									require(['pages/wechat/mass/search.vue'], resolve);
								}
							},
							'/filter': {
								breadcrumb: '筛选群发',
								component: function(resolve) {
									require(['pages/wechat/mass/filter.vue'], resolve);
								}
							},
							'/media': {
								breadcrumb: '新增多媒体',
								component: function(resolve) {
									require(['pages/wechat/mass/media.vue'], resolve);
								}
							}
						}
					},
					'/message': {
						breadcrumb: '消息管理',
						component: Wechat,
						subRoutes: {
							'/send': {
								breadcrumb: '发送消息维护',
								component: function(resolve) {
									require(['pages/wechat/message/send.vue'], resolve);
								}
							},
							'/receive': {
								breadcrumb: '收到消息查询',
								component: function(resolve) {
									require(['pages/wechat/message/receive.vue'], resolve);
								}
							}
						}
					}
				}
			},
			"/APP": {
				breadcrumb: 'APP管理',
				component: Mounter,
				subRoutes: {
					"/version": {
						breadcrumb: '软件管理',
						component: Mounter,
						subRoutes: {
							'/create': {
								breadcrumb: '软件添加',
								component: function(resolve) {
									require(['pages/APP/version/create.vue'], resolve);
								}
							},
							'/list': {
								breadcrumb: '软件维护',
								component: function(resolve) {
									require(['pages/APP/version/list.vue'], resolve);
								}
							}
						}
					}

				}
			}

		}
	}
}

router.map(map);

/*
router.beforeEach(function ({ to, from, redirect, next }) {
	if (to.path !== '/login' && (!localStorage.getItem('id_token'))) {
		redirect('/login')
	} else {
		next();
	}
	$("#mounter").empty();
	window.scrollTo(0, 0);

})
*/

router.beforeEach(function({
	to,
	from,
	redirect,
	next
}) {

	if (!sessionStorage.getItem('start')) {
		localStorage.clear();
	}

	if (to.path == '/login') {
		next()
	} else if (localStorage.getItem('id_token')) {
		let list = JSON.parse(localStorage.getItem('list_mid'));
		if (list.length == 0 || to.path == '/home' || localStorage.getItem('get_id')) {
			next()
		} else {
			redirect('/')
		}
	} else {
		redirect('/login')
	}

	$("#mounter").empty();
	$("#other-content").empty();
	window.scrollTo(0, 0);

})

import store from 'lib/vuex/store.js'
router.afterEach(({
	to
}) => {
	let path = to.path;
	store.dispatch('set_path', path)
});

router.alias({
	'/': '/home',
})

router.start(Root, '#app');

export default router
